function groupThePeople(groupSizes: number[]): number[][] {
    // 思路是先合并
    interface length {
        [key: string]  : number[]
    }
    let ansArr: number[][] = []
    let obj: length = {}
    groupSizes.forEach((item,index) => {
        if(obj?.[item]) {
            obj[item].push(index)
        }else {
            obj[item] = [index]
        }
    })
    console.log(obj)
    for (let k in obj) {
        console.log(k)
        let numK = Number(k)
        for (let i=0;i<obj[k].length;i+=numK){
            console.log(i,obj[k].length)
            ansArr.push(obj[k].slice(i,i+numK))
        }
        
    }
    return ansArr
};

const groupSizes: number[] = [2,2,1,1,1,1,1,1]
console.log(groupThePeople(groupSizes))